package org.linlinjava.litemall.db.service;

import com.github.pagehelper.PageHelper;
import org.linlinjava.litemall.db.dao.LitemallMechanismGoodsCheckMapper;
import org.linlinjava.litemall.db.domain.LitemallMechanismGoodsCheck.Column;
import org.linlinjava.litemall.db.domain.*;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class LitemallMechanismGoodsCheckService {
    @Resource
    private LitemallMechanismGoodsCheckMapper mechanismGoodsCheckMapper;

    public List<LitemallMechanismGoodsCheck> querySelective(Integer page, Integer limit,Byte value, String sort, String order) {
        LitemallMechanismGoodsCheckExample example = new LitemallMechanismGoodsCheckExample();
        LitemallMechanismGoodsCheckExample.Criteria criteria = example.createCriteria();
        if(!StringUtils.isEmpty(value)){
            criteria.andIsCheckEqualTo(value);
        }
        criteria.andDeletedEqualTo(false);
        PageHelper.startPage(page, limit);
        return mechanismGoodsCheckMapper.selectByExample(example);
    }

    public int countSelective(Integer page, Integer size,Byte value, String sort, String order) {
        LitemallMechanismGoodsCheckExample example = new LitemallMechanismGoodsCheckExample();
        LitemallMechanismGoodsCheckExample.Criteria criteria = example.createCriteria();
        if(!StringUtils.isEmpty(value)){
            criteria.andIsCheckEqualTo(value);
        }
        criteria.andDeletedEqualTo(false);
        return (int)mechanismGoodsCheckMapper.countByExample(example);
    }

    public void updateById(LitemallMechanismGoodsCheck goods) {
        mechanismGoodsCheckMapper.updateByPrimaryKeySelective(goods);
    }
    public void updateAllByIds(Integer type,List<String> ids,String reson){
        mechanismGoodsCheckMapper.updateAllByIds(type,ids,reson);
    }
    public void add(LitemallMechanismGoodsCheck check) {
        mechanismGoodsCheckMapper.insertSelective(check);
    }

    public List<LitemallMechanismGoodsCheck> findByGoodsId(Integer id) {
        LitemallMechanismGoodsCheckExample example = new LitemallMechanismGoodsCheckExample();
        example.or().andGoodsIdEqualTo(id);
        example.orderBy(Column.addTime.desc());
        return mechanismGoodsCheckMapper.selectByExample(example);
    }

    public void updateDeletedByGoodsId(Integer id) {
        mechanismGoodsCheckMapper.updateDeletedByGoodsId(id);
    }
}
